<?php
namespace App\Repos;
use App\Models\Shop;
use App\Models\ShopUser;
use App\Models\ShopEnvelope;

use App\Services\RedisService;
use Carbon\Carbon;


class ShopUserRepo
{
	public static function  getList($where=[],$num=10)
	{	   
	  	$list = ShopUser::where($where)->paginate($num); 
	  	return $list;     
	}

	public static function get()
	{
		return  ShopUser::select(['id','name'])->get();
	}

	public static function create($data)
	{		
		$rs = ShopUser::create($data);
		return $rs;
	}

	public static function find($where,$column=['*'])
	{	
		
		$data =  ShopUser::where($where)->select($column)->first();
		return $data;
		
	}

	public static function findByToken($token)
	{		
		$shop = RedisService::get('fruit:shops:user'.$token);
		if($shop) {
			return json_decode($shop);
		} 

		$shop =  ShopUser::where(['token'=>$token])->first();

		if($shop) {
			RedisService::set('fruit:shops:user'.$token,$shop->toJson());
			return $shop;	
		}
		
		return false;
		
	}

	public static function update($where,$data)
	{
		$rs['status'] = false;

		$flag = ShopUser::where($where)->update($data);	

		if($flag) {
			$rs['status'] = true;
			return $rs;
		}

		return $rs;
	}

	public static function del($id)
	{
		return ShopUser::destroy($id);
	}

	

	

	

	

	

	

	

	
	
	
}